//
//  LoginView.m
//  NoNeedle
//
//  Created by Ming Tian on 2017/3/8.
//  Copyright © 2017年 Ming Tian. All rights reserved.
//

#import "LoginView.h"

const double loginButtonRate = 90.0f/450.0f;

@implementation LoginView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if(self) {
        [self setupSubviews];
    }
    return self;
}

- (void)setupSubviews {
    self.usernameLeftImageView = [[UIImageView alloc]init];
    self.usernameLeftImageView.image = [UIImage imageNamed:@"icon_login_user"];
    [self addSubview:self.usernameLeftImageView];
    
    self.usernameTextField = [[UITextField alloc]init];
    self.usernameTextField.font = [UIFont systemFontOfSize:15];
    self.usernameTextField.placeholder = @"手机号";
    self.usernameTextField.keyboardType = UIKeyboardTypeNumberPad;
    self.usernameTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    [self addSubview:self.usernameTextField];
    
    self.sepLine1 = [[UIView alloc]init];
    self.sepLine1.backgroundColor = RGBa(0xe2e2e2);
    [self addSubview:self.sepLine1];
    
    self.passwordLeftImageView = [[UIImageView alloc]init];
    self.passwordLeftImageView.image = [UIImage imageNamed:@"icon_login_passworld"];
    [self addSubview:self.passwordLeftImageView];
    
    self.passwordTextField = [[UITextField alloc]init];
    self.passwordTextField.font = [UIFont systemFontOfSize:15];
    self.passwordTextField.placeholder = @"密码";
    self.passwordTextField.secureTextEntry = YES;
    self.passwordTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    [self addSubview:self.passwordTextField];
    
    self.sepLine2 = [[UIView alloc]init];
    self.sepLine2.backgroundColor = RGBa(0xe2e2e2);
    [self addSubview:self.sepLine2];
    
    self.forgetPasswordButton = [[UIButton alloc]init];
    self.forgetPasswordButton.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.forgetPasswordButton setTitle:@"忘记密码" forState:UIControlStateNormal];
    [self.forgetPasswordButton setTitleColor:NavBackColor forState:UIControlStateNormal];
    [self addSubview:self.forgetPasswordButton];
    
    self.loginButton = [[UIButton alloc]init];
    self.loginButton.titleLabel.font = [UIFont systemFontOfSize:16];
    [self.loginButton setTitle:@"登录" forState:UIControlStateNormal];
    [self.loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    self.loginButton.backgroundColor = themeColor;
    self.loginButton.layer.cornerRadius = screenW*0.65*loginButtonRate/2;
    self.loginButton.layer.masksToBounds = NO;
    [self.loginButton setBackgroundImage:ImageName(@"icon_login__buttton_bg") forState:UIControlStateNormal];
    [self addSubview:self.loginButton];
    // 按钮投影
//    self.loginButton.layer.shadowColor = themeColor.CGColor;
//    self.loginButton.layer.shadowOpacity = 0.6f;
//    self.loginButton.layer.shadowOffset = CGSizeMake(0,2);
//    self.loginButton.layer.shadowRadius = 4;
    
    
    
    [self setupConstraints];
}
- (void)setupConstraints {
    [self.sepLine1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(70);
        make.centerX.equalTo(self);
        make.width.mas_equalTo(self).multipliedBy(0.75);
        make.height.mas_equalTo(1);
    }];
    [self.usernameLeftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.sepLine1).offset(10);
        make.bottom.equalTo(self.sepLine1).offset(-7);
        make.width.height.mas_equalTo(30);
    }];
    [self.usernameTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.usernameLeftImageView.mas_right).offset(10);
        make.bottom.equalTo(self.usernameLeftImageView);
        make.right.equalTo(self.sepLine1);
        make.height.equalTo(self.usernameLeftImageView);
    }];
    [self.passwordLeftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.sepLine1).offset(7);
        make.left.equalTo(self.usernameLeftImageView);
        make.width.height.equalTo(self.usernameLeftImageView);
    }];
    [self.passwordTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.passwordLeftImageView);
        make.left.equalTo(self.usernameTextField);
        make.right.equalTo(self.usernameTextField);
        make.height.equalTo(self.usernameTextField);
    }];
    [self.sepLine2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.passwordLeftImageView.mas_bottom).offset(7);
        make.centerX.equalTo(self.sepLine1);
        make.width.equalTo(self.sepLine1);
        make.height.mas_equalTo(1);
    }];
    [self.forgetPasswordButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.sepLine2).offset(5);
        make.right.equalTo(self.sepLine2);
    }];
    [self.loginButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self.forgetPasswordButton.mas_bottom).offset(30);
        make.width.equalTo(self).multipliedBy(0.65);
        make.height.mas_equalTo(80);
    }];
}

@end
